
<script language="JavaScript" type="text/javascript">
	function confirmDelete(anchor){
		if (confirm('Are you sure you would like to delete this?')){
			anchor.href += '&confirm=1';
      	return true;
    	}
    	
    	return false;
	}
</script>

<style type="text/css">
	body {margin:0px;padding:0px;color:#000000; font-size:11px;background-color:#F2F2F2}
	a { color:#000000;padding-right:5px}
	a:hover { color:#000000; text-decoration:underline}
</style>

<br />

<?php

	require_once(dirname(__FILE__)."/../core/safeParam.php");

	require_once('../includes/config.php');
	require_once('../core/database.php');
	
	$editsequence = $edit;
	$parentid = $_GET['id'];
	
	// sub pages list
	$query    = $database->query("SELECT * FROM pages WHERE parent = $parentid ORDER by id ");
	
	while ($list = mysql_fetch_array($query)) {
		$id          = $list['id'];
  		$date        = $list['date'];
  		$title       = $list['title'];
  		$pagename    = $list['pagename'];
  		$linktitle   = $list['linktitle'];
  		$description = $list['description'];
  		$content     = $list['content'];
  		$menuitem    = $list['menuitem'];
  		$hassub      = $list['hassub'];
  		$parent      = $list['parent'];
  		$status      = $list['status'];
  		
  		if ($status == '2') {
  			$editlink = 'index.php?edit=pages&function=edit-link&id=' . $id . '';
  		} else {
  			$editlink = 'index.php?edit=pages&id=' . $id . '';
  		}
  		
  		$sublist .= '<a target="_top" href="index.php?edit=pages&edit=' . $pagename . '&id=' . $id . '">' . $pagename . '</a> ';
  		$num_rows = mysql_num_rows($query);
  		$pos      = $list['pos'];
  
  		if ($menuitem == '1') {
  			$linktomenu = '<span style="color:green">Page Is in submenu</span>';
    		$csstyle    = 'text-indent: 20px';
  		} elseif ($menuitem == '0') {
  			$linktomenu = '<span style="color:red">Page is in Top Menu</span>';
    		$csstyle    = 'text-indent: 0px';
  		} //$menuitem == '0'
  		
  		if ($pagename == 'Houses') {
  			$addpage = '<a target="_top"  href="index.php?edit=pages&function=add" style="color:green">&nbsp;&nbsp;&nbsp;(Add New House Type)</a>';
  		} else {
  			$addpage = '';
  		}
  		
  		if ($linktitle == 'Home') {
  			$delete = '<a target="_top"  href="#" alt="cannot delete this page">Delete</a>';
  		} elseif ($linktitle == 'Contact') {
  			$delete = '<a target="_top"  href="#" alt="cannot delete this page">Delete</a>';
  		} else {
  			$delete = '<a target="_top"  href="../functions/pages.php?function=delete&id=' . $id . '&parent=' . $parent . '" onclick="return confirmDelete(this);">Delete</a>';
  		}
  		
  		$row_color = ($row_count % 2) ? $color1 : $color2;
  		
  		if ($hassub == '1') {
  			$removesub = '<a target="_top"  style="color:green" href="../functions/pages.php?function=remove-sub&id=' . $id . '">Remove Sub-Menu</a>';
  		} else {
  			$removesub = '<span style="color:red">no sub-menu</span>';
  		}
  		
  		$names .= '
  		<tr>
  			<td bgcolor="' . $row_color . '" nowrap>
  				<a target="_top"  style="' . $csstyle . '" href="' . $editlink . '">&bull; ' . $linktitle . ' ' . $addpage . '</a>
  				<br>
			</td>
			
			<td>
				<a target="_top"  href="' . $editlink . '">Editar</a> | 
				' . $delete . ' | <a target="_blank" href="' . $siteroot . 'pages.php?id=' . $id . '">Vista Previa</a>
			</td>
			
			<td>
				<form action="../functions/pages.php?function=order" method="post" target="_blank">
					<input name="pos" type="text" size="1" value="' . $pos . '">
					<input name="posid" type="hidden" value="' . $id . '">
					<input type="submit" value="Guardar" />
				</form>
			</td>
		</tr>';
  		
  		$row_count++;
?>

<?php
	} //$list = mysql_fetch_array($query)
	
	// sub pages list
	if ($sublist == '') {
		echo '
		<h3>
			<a target="_top" href="index.php?edit=pages&function=add&subid=' . $id . '&subpagename=' . $pagename . '">Sorry no sub pages, click here to add one</a>
		</h3>';
	} else {
?>					
	
	<p>Click on a page below to edit the page or  access the sub-pages of that page</p>
	<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="style2">
		<tr bgcolor="#f4f7f4">
			<td width="33%"><strong>Nombre de la Página</strong></td>
			<td width="33%"><strong>Funciones</strong></td>
	  		<td width="33%"><strong>Posición en el Menu</strong></td>
	  	</tr>

<?php
  echo $names;
?>
	
	</table>
	
<?php
}
?>
